package link.cocoon.common.runner;

import javax.annotation.Resource;
import link.cocoon.common.global.config.ProjectConstantConfig;
import link.cocoon.system.entity.User;
import link.cocoon.system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;



@Component
@Slf4j
public class AfterRunner implements CommandLineRunner {

  @Resource
  private UserService userService;

  @Resource
  private ProjectConstantConfig projectConstantConfig;

  @Override
  public void run(String... args) {
    User user = userService.getByUsername("admin");
    if (user == null) {
      log.error("不存在超级管理员，创建中");
      user = new User();
      user.setUsername("admin");
      user.setPassword("admin");
      user.setPhone("17799771021");
      userService.create(user);
      log.info("创建成功");
    }
    log.info("项目名:{}",projectConstantConfig.getName());
    log.warn("SpringBoot 已经启动");
  }
}
